import { createRouter, createWebHashHistory } from 'vue-router'
export const routes = [
  { path: '/login', name: 'login', component: () => import("@/views/login/LoginView.vue") },
  {
    path: '/', name: 'home', meta: { requiresAuth: true, title: '系统首页', iconName: "HomeFilled" }, redirect: '/home', component: () => import("@/layout/LayoutView.vue"),
    children: [
      { path: '/home', title: '系统首页',meta: { requiresAuth: true }, component: () => import("@/views/home/HomeView.vue") }
    ]
  },
  {
    path:"/np",name:'np',redirect:'np',component:()=>import("@/layout/LayoutView.vue"),
    children:[
      {path:'/np',component:()=>import('@/views/home/np.vue')}
    ]
  },
  {
    path: '/banner', name: 'banner', meta: { requiresAuth: true, title: '轮播图管理', iconName: "HelpFilled" }, redirect: '/banner/list', component: () => import("@/layout/LayoutView.vue"),
    children: [
      {
        path: '/banner/list', meta: { requiresAuth: true, title: '轮播图管理', iconName: "MessageBox" }, redirect: '/banner/list/home', component: () => import("@/views/banner/BannerView.vue"),
        children: [
          { path: '/banner/list/home', meta: { requiresAuth: true, title: '首页轮播图管理', iconName: "MessageBox" }, component: () => import("@/views/banner/components/BannerHome.vue") },
          { path: '/banner/list/kind', meta: { requiresAuth: true, title: '分类轮播图管理', iconName: "MessageBox" }, component: () => import("@/views/banner/components/BannerKind.vue") }
        ]
      },
      { path: '/banner/add', meta: { requiresAuth: true, iconNAme: 'Edit', title: "轮播图添加" }, component: () => import("@/views/banner/components/BannerAdd.vue") }
    ]
  },
  {
    path: '/pro', name: 'pro', meta: { requiresAuth: true, title: '产品管理', iconName: "Menu" }, redirect: '/pro/list', component: () => import("@/layout/LayoutView.vue"),
    children: [
      { path: '/pro/list', meta: { requiresAuth: true, title: '产品列表', iconName: "Menu" }, component: () => import("@/views/pro/components/ProList.vue") },
      { path: '/pro/filter', meta: { requiresAuth: true, title: '筛选列表', iconName: "Menu" }, component: () => import("@/views/pro/components/ProFilter.vue") }
    ]
  },
  {
    path: '/account', name: 'account', meta: { requiresAuth: true, title: '账户管理', iconName: "UserFilled" }, redirect: '/account', component: () => import("@/layout/LayoutView.vue"),
    children: [
      { path: '/account/admin', meta: { requiresAuth: true, title: '管理员列表', iconName: "User" }, component: () => import("@/views/account/components/MyAdmin.vue") },
      { path: '/account', meta: { requiresAuth: true, title: '用户列表', iconName: "User" }, component: () => import("@/views/account/components/MyUser.vue") }
    ]
  },
  {
    path: '/import-export', name: 'import-export', meta: { requiresAuth: true, title: '导入以及导出', iconName: "Tools" }, redirect: '/import-export', component: () => import("@/layout/LayoutView.vue"), children: [
      { path: '/import-export/import', meta: { requiresAuth: true, title: '导入', iconName: "Setting" }, component: () => import("@/views/import-export/components/ImportCom.vue") },
      { path: '/import-export/export', meta: { requiresAuth: true, title: '导出', iconName: "Setting" }, component: () => import("@/views/import-export/components/ExportCom.vue") },
    ]
  },
]
const router = createRouter({
  history: createWebHashHistory(),
  routes
})

import { useUserStore } from '@/stores/useUser'
router.beforeEach((to, from) => {
  const useUser = useUserStore()
  if (to.meta.requiresAuth && !useUser.isLogin) {
    return {
      path: '/login',
      query: { redirect: to.fullPath }
    }
  }
})

export default router
